package com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.dao;

import com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.entity.GuaranteeMoney;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class GuaranteeMoneyDao {

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    private final String insertGuaranteeMoneySql = "INSERT INTO sw_guarantee_money (grtInfoSeqNo, guaId, data, socialCreditCode, genDateStr, payType, storageTime)" +
            " VALUES (:grtInfoSeqNo, :guaId, :data, :socialCreditCode, :genDateStr, :payType, :storageTime)";

    public void save(List<GuaranteeMoney> list) {
        SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(list);
        namedParameterJdbcTemplate.batchUpdate(insertGuaranteeMoneySql, batch);
    }


    private final String deleteGuaranteeMoneySql = "DELETE FROM sw_guarantee_money WHERE grtInfoSeqNo IN (:grtInfoSeqNos)";

    public void deleteBy(List<String> grtInfoSeqNos) {
        Map<String, Object> params = new HashMap<>();
        params.put("grtInfoSeqNos", grtInfoSeqNos);
        namedParameterJdbcTemplate.update(this.deleteGuaranteeMoneySql, params);
    }
}
